package com.sun;

/**
 * https://leetcode.cn/problems/palindrome-number/
 */
public class Test9IsPalindrome {
    public static void main(String[] args) {
        boolean palindrom1 = isPalindrom1(11);
        System.out.println(palindrom1);

    }

    /**
     * 自己
     */
    public static boolean isPalindrom1(int x){
        /*if (x >= 0 && x < 10){
            return true;
        }else if (x < 0){
            return false;
        }*/
        if (x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }
        String s = String.valueOf(x);
        for (int i = 0,j = s.length() - 1; i < s.length() && j >= 0;) {
            if (i >= j){
                return true;
            }
            if (s.charAt(i) == s.charAt(j)){
                j--;
                i++;
            }else {
                return false;
            }
        }
        return false;
    }

    /**
     * 方法2：力扣官方
     */
    public static boolean isPalindrome2(int x){
        if (x < 0 || (x % 10 == 0 && x != 0)) {
            return false;
        }
        int temp = 0;
        while (x > temp){
            temp = temp * 10 + x  % 10;
            x /= 10;
        }
        return x == temp || x == temp / 10;
    }
}
